﻿Imports System.Data.OleDb
Public Class AddingPhone
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt_SubmitPhone.Click
        Dim myIdentifierCode = Guid.NewGuid()
         Dim newFileName As String = Guid.NewGuid().ToString() & ".jpg"
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("Phones").ConnectionString)
        Dim SqlString As String = "Insert into Phones(BrandName,PhoneName,Picture,PhoneVersion,DateRelease,Review) Values (@f1,@f2,@f3,@f4,@f5,@f6)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_BrandName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_PhoneName.Text)
        cmd.Parameters.AddWithValue("@f3", "Pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f4", dd_PhoneVersion.SelectedValue)
        cmd.Parameters.AddWithValue("@f5", tb_DateRelease.Text)
        cmd.Parameters.AddWithValue("@f6", tb_PhoneReview.Text)
        Dim PicturesFolder As String = Request.MapPath("Pictures")
        fu_PhonePicture.SaveAs(PicturesFolder & "/" & newFileName)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        Response.Redirect("Thanks.aspx")
    End Sub
End Class